﻿using BlogAssignment.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BlogAssignment
{
    //The class is sealed. This is unnecessary, strictly speaking, due to the above point, but may help the JIT to optimise things more. 
    public sealed class BlogDatabase
    {
        #region Singleton
        private static BlogDatabase _instance = null;

        private BlogDatabase()
        {
            _blogPost = new List<BlogPost>();

            _blogPost.Add(new BlogPost {Title = "Title! ", Text = "Blah!",UserName = "V" }
                );

        }
        //A static variable which holds a reference to the single created instance, if any. 
        public static BlogDatabase Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new BlogDatabase();
                }

                return _instance;
            }
        }


        #endregion
        //Variable
        private List<BlogPost> _blogPost;

        public List<BlogPost> GetBlogPosts()
        {
            return _blogPost;
        }
    }
}